package com.jiutong.meipenggang.ui.activitys;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiutong.meipenggang.R;
import com.jiutong.meipenggang.base.BaseActivity;
import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.entity.PayInBean;
import com.jiutong.meipenggang.entity.SurePayInBean;
import com.jiutong.meipenggang.http.model.interfaces.MeiCaiBaoBiz;
import com.jiutong.meipenggang.http.present.MeiCaiBaoPresent;
import com.jiutong.meipenggang.utils.SpConfig;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PayInActivity extends BaseActivity implements MeiCaiBaoBiz {


    @Bind(R.id.imageView)
    ImageView imageView;
    @Bind(R.id.rl_common_title_back)
    RelativeLayout rlCommonTitleBack;
    @Bind(R.id.tv_common_title)
    TextView tvCommonTitle;
    @Bind(R.id.et_buy_price)
    EditText etBuyPrice;
    @Bind(R.id.tv_wanner_earn_day)
    TextView tvWannerEarnDay;
    @Bind(R.id.rl_select_red_pocket)
    RelativeLayout rlSelectRedPocket;
    @Bind(R.id.iv_balance_pay_in)
    ImageView ivBalancePayIn;
    @Bind(R.id.tv_balance_pay_in)
    TextView tvBalancePayIn;
    @Bind(R.id.rl_balance_pay)
    RelativeLayout rlBalancePay;
    @Bind(R.id.iv_quick_pay)
    ImageView ivQuickPay;
    @Bind(R.id.iv_bank_icon)
    ImageView ivBankIcon;
    @Bind(R.id.rl_quick_pay)
    RelativeLayout rlQuickPay;
    @Bind(R.id.tv_need_pay)
    TextView tvNeedPay;
    @Bind(R.id.iv_support)
    ImageView ivSupport;
    @Bind(R.id.tv_mpg_fuwu)
    TextView tvMpgFuwu;
    @Bind(R.id.activity_pay_in)
    RelativeLayout activityPayIn;
    @Bind(R.id.btn_sure_payin)
    Button btnSurePayin;
    private MeiCaiBaoPresent meiCaiBaoPresent;

    private int read = 0;
    private String redid =110+"";
    private String price;
    private double balance;


    @Override
    public int getLayoutResouceId() {
        return R.layout.activity_pay_in;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    }

    @Override
    protected void initDate(Bundle savedInstanceState) {
        meiCaiBaoPresent = new MeiCaiBaoPresent(this, this);
        meiCaiBaoPresent.payin();
    }

    @Override
    public void onSuccess2(Object object) {
        SurePayInBean respone= (SurePayInBean) object;
        if (respone.getError() == -1) {
            SpConfig.getInstance().edit().putString(Constants.TOKEN, respone.getToken()).commit();

        } else {
            toastShortShow(respone.getMsg());

        }
    }

    @Override
    public void onError2(Throwable e) {

    }

    @Override
    public void onSuccess(Object object) {
        PayInBean respone = (PayInBean) object;
        if (respone.getError() == -1) {
            SpConfig.getInstance().edit().putString(Constants.TOKEN, respone.getToken()).commit();
            tvBalancePayIn.setText(respone.getBalance() + "");
        } else {
            toastShortShow(respone.getMsg());
        }

    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public int getOpt() {
        return 0;
    }


    @OnClick({R.id.rl_select_red_pocket, R.id.rl_balance_pay, R.id.rl_quick_pay, R.id.iv_support, R.id.tv_mpg_fuwu, R.id.activity_pay_in, R.id.btn_sure_payin})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_select_red_pocket:
                break;
            case R.id.rl_balance_pay:
                ivBalancePayIn.setImageResource(R.mipmap.icon_out_selected);
                ivQuickPay.setImageResource(R.mipmap.icon_out_unchecked);
                break;
            case R.id.rl_quick_pay:
                ivBalancePayIn.setImageResource(R.mipmap.icon_out_unchecked);
                ivQuickPay.setImageResource(R.mipmap.icon_out_selected);
                break;
            case R.id.iv_support:
                if (read == 0) {
                    ivSupport.setImageResource(R.mipmap.icon_out_selected);
                    read = 1;
                } else {
                    ivSupport.setImageResource(R.mipmap.icon_out_unchecked);
                    read = 0;
                }
                break;
            case R.id.tv_mpg_fuwu:
                openActivity(AgreementActivity.class);
                break;
            case R.id.activity_pay_in:
                break;
            case R.id.btn_sure_payin:
                if (read == 0) {
                    toastShortShow("请先同意美鹏港服务协议!");
                } else {
                    meiCaiBaoPresent.surePayIn(redid,price);
                }
                price = etBuyPrice.getText().toString().trim();
                if (TextUtils.isEmpty(price)) {
                    toastShortShow("请输入转入金额!");
                }



                break;
        }
    }


}
